// pages2/pages/person/billOrder/index.js
const $api = require('../../../../request/api.js').API;
import Toast from '../../../../miniprogram_npm/@vant/weapp/toast/toast';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    businessId: '',
    pageNo: 1,
    pageSize: 15,
    totalPage: '',
    payType: '',
    orderIds: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const { businessId, payType, orderIds } = options;
    this.setData({
      businessId,
      payType,
      orderIds
    });
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},
  getData(isAdd) {
    const { pageNo, pageSize, businessId, payType, orderIds } = this.data;
    const params = {
      pageNo,
      pageSize,
      payType,
      businessId,
      orderIds
    };
    $api.orderList(params).then(res => {
      const { list, totalPage } = res.data.data;
      if (isAdd) {
        this.setData({
          dataList: dataList.concat(list)
        });
      } else {
        this.setData({
          dataList: list,
          totalPage
        });
      }
    });
  },
  toDetail(e) {
    let id = e.currentTarget.dataset.id;
    // + '&mainFlag=' + this.data.mianFlag
    wx.navigateTo({
      url: '/subcontract/order/pages/details/index?orderId=' + id
    });
  },
  callPhone(e) {
    let phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone, //仅为示例，并非真实的电话号码
      success: function () {
        console.log('拨打电话成功！');
      },
      fail: function () {
        console.log('拨打电话失败！');
      }
    });
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let { pageNo, totalPage } = this.data;
    if (pageNo == totalPage) {
      Toast('到底了');
      return;
    }
    this.setData({
      pageNo: ++pageNo
    });
    this.getData(isAdd);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {}
});
